package com.gg.user.gguser.service.impl;

import com.gg.user.gguser.dao.AppGetItemsDaoMapper;
import com.gg.user.gguser.dao.GgCompanyItemsAllDaoMapper;
import com.gg.user.gguser.dao.GgSearchMapper;
import com.gg.user.gguser.dataobject.GgBusinessOpportunityDtaobject;
import com.gg.user.gguser.dataobject.GgContractDataobject;
import com.gg.user.gguser.service.GgRecommendServe;
import com.gg.vo.return_format;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangxinlei
 * @date 2020/4/29
 */
@Service
public class GgRecommendServeImpl implements GgRecommendServe {

    @Autowired
    private GgSearchMapper ggSearchMapper;

    @Autowired
    private GgCompanyItemsAllDaoMapper ggCompanyItemsAllDaoMapper;

    @Autowired
    private AppGetItemsDaoMapper appGetItemsDaoMapper;

    /**
     * APP 首页推荐
     * @param response
     * @param request
     * @return
     * @throws Exception
     */
    @Override
    public Object getRecommend(HttpServletResponse response, HttpServletRequest request) throws Exception {
        try {

            return return_format.return_format_All(0,ggSearchMapper.getRecommend(),"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器报错！");
        }
    }

    /**
     * APP 公司详情
     */
    @Override
    public Object getRecommendItems(HttpServletResponse response, HttpServletRequest request, String id) throws Exception {
        try {
            return return_format.return_format_All(0,ggCompanyItemsAllDaoMapper.getGgCompanyItemsAllItems(id),"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器报错！");
        }
    }

    /**
     * APP 信息页面搜索
     */
    @Override
    public Object getRecommendQItems(HttpServletResponse response, HttpServletRequest request, String q,Integer page,Integer pageNumber) throws Exception {
        // 去数据库拿十个默认的
        try {
            List<Map<Object,Object>> ListCompanySearch =  ggSearchMapper.getCompanySearch(page*pageNumber,pageNumber);
            return return_format.return_format_All(0, ListCompanySearch,"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器报错！");
        }
    }

    /**
     * APP 今日需要联系客户
     */
    @Override
    public Object todayContactCustomer(HttpServletResponse response, HttpServletRequest request, Integer page, Integer pageNumber) throws Exception {
        try {
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
            String dataString = formatter.format(new Date(System.currentTimeMillis()));
            List<GgBusinessOpportunityDtaobject> listGgBusinessOpportunityDtaobject = appGetItemsDaoMapper.getTodayContactCustomer(dataString);
            Integer GgBusinessOpportunityDtaobjectCount = appGetItemsDaoMapper.GgBusinessOpportunityDtaobjectCount(dataString);
            Map dataMap = new HashMap();
            dataMap.put("data",listGgBusinessOpportunityDtaobject);
            dataMap.put("dataCount",GgBusinessOpportunityDtaobjectCount);
            return return_format.return_format_All(0, dataMap,"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器报错！");
        }
    }

    /**
     * 马上到期客户
     */
    @Override
    public Object todayDueCustomers(HttpServletResponse response, HttpServletRequest request, Integer page, Integer pageNumber) throws Exception {
        try {
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
            String dataString = formatter.format(new Date(System.currentTimeMillis()));
            List<GgContractDataobject> listGgBusinessOpportunityDtaobject = appGetItemsDaoMapper.getGgContractDataobject(dataString);
            Integer GgBusinessOpportunityDtaobjectCount = appGetItemsDaoMapper.getGgContractDataobjectCount(dataString);
            Map dataMap = new HashMap();
            dataMap.put("data",listGgBusinessOpportunityDtaobject);
            dataMap.put("dataCount",GgBusinessOpportunityDtaobjectCount);
            return return_format.return_format_All(0, dataMap,"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器报错！");
        }
    }


}
